package com.fjwt.gz.mgr.ctrl.assetLevel;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson2.JSONObject;
import com.fjwt.gz.core.model.ApiRes;
import com.fjwt.gz.mgr.ctrl.CommonCtrl;
import com.fjwt.gz.service.impl.AssetMonthService;
import com.fjwt.gz.service.impl.AssetQuarterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Slf4j
@RestController
@RequestMapping("/api/asset")
public class AssetLevelTask extends CommonCtrl {

    @Autowired
    private AssetMonthService assetMonthService;
    @Autowired
    private AssetQuarterService assetQuarterService;

    @PostMapping("/process")
    public ApiRes processUserAssetLevels() {
        log.info("开始进入用户资产等级任务{}", DateUtil.now());
        assetMonthService.processUserAssetLevels();
        return ApiRes.ok();
    }

    @PostMapping("/quarter")
    public ApiRes quarterAssetLevel() {
        String cstmno = getObject(JSONObject.class).getString("cstmno");
        Long userId = getCurrentUser().getUserId();
        assetQuarterService.quarterAssetLevel(userId, cstmno, null);
        return ApiRes.ok();
    }

    @PostMapping("/quarterselect")
    public ApiRes quarterAssetLevelselect() {
        log.info("开始进入用户资产等级任务{}", DateUtil.now());
        assetQuarterService.processQuarter();
        return ApiRes.ok();
    }
}
